﻿<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:Converters="clr-namespace:GraphLight.Converters"
        xmlns:Controls="clr-namespace:GraphLight.Controls" xmlns:Drawing="clr-namespace:GraphLight.Drawing">

    <!-- Common resources -->
    <Converters:PointsToPolyLineConverter x:Key="polyLineConverter" />
    <ItemsPanelTemplate x:Key="canvasPanelTemplate">
        <Canvas />
    </ItemsPanelTemplate>

    <!-- Control point -->
    <DataTemplate x:Key="controlPointTemplate">
        <Ellipse Width="8" Height="8" Margin="-4,-4,0,0" Fill="White" Stroke="Red" StrokeThickness="1" />
    </DataTemplate>
    <Style x:Key="controlPointContainerStyle" TargetType="ContentPresenter">
        <Setter Property="Controls:DragDropManager.AllowDrag" Value="True" />
        <Setter Property="Canvas.Left" Value="{Binding X, Mode=TwoWay}" />
        <Setter Property="Canvas.Top" Value="{Binding Y, Mode=TwoWay}" />
    </Style>

    <!-- Graph -->
    <ControlTemplate x:Key="diagramTemplate" TargetType="Drawing:GraphControl">
        <Grid Background="Transparent" x:Name="LayoutRoot">
            <ScrollViewer x:Name="scrollViewer" HorizontalScrollBarVisibility="Auto"
                    VerticalScrollBarVisibility="Auto" Background="{x:Null}">
                <Grid x:Name="mainGrid" ShowGridLines="True" Background="Transparent"
                        Controls:DragDropManager.AllowDrop="true">
                    <Path x:Name="line" Stroke="Gray" StrokeThickness="0.5" StrokeDashArray="4,8"
                            Data="{Binding SelectedEdge.Data.Points, Converter={StaticResource polyLineConverter}}"
                            Height="{Binding Graph.Height}" Width="{Binding Graph.Width}" />
                    <Canvas x:Name="graphCanvas" Height="{Binding Graph.Height}" Width="{Binding Graph.Width}"
                            Background="Transparent" />
                    <Controls:ItemsControlEx x:Name="controlPoints" HorizontalContentAlignment="Stretch"
                            ItemsSource="{Binding SelectedEdge.Data.DraggablePoints}"
                            ItemsPanel="{StaticResource canvasPanelTemplate}"
                            ItemTemplate="{StaticResource controlPointTemplate}"
                            ItemContainerStyle="{StaticResource controlPointContainerStyle}"
                            Height="{Binding Graph.Height}" Width="{Binding Graph.Width}" />
                </Grid>
            </ScrollViewer>
        </Grid>
    </ControlTemplate>

    <Style TargetType="Drawing:GraphControl">
        <Setter Property="Template" Value="{StaticResource diagramTemplate}" />
    </Style>

</ResourceDictionary>